<script lang="ts">
  import { uiHelpers } from 'svelte-5-ui-lib'
  import CodeEditor from '$lib/components/EditorComponents/CodeEditor.svelte'
  import DrawerBox from '$lib/components/DrawerBox.svelte'

  const reqeustJSON = {
    platform: 'E-Commerce Plus 2024',
    version: '2.3.1',
    timestamp: '2024-02-15T14:30:45Z',
    metadata: {
      licenseKey: 'a3b8c2d7-e4f5-4a7d-9c3b-6d8e9f7a2b1c',
      apiEndpoints: ['/users/{id}/orders', '/products/search', '/analytics/sales'],
    },
    users: [
      {
        userId: 'USR-2024-0257',
        personalInfo: {
          name: '张伟',
          email: 'zhang.wei@example.com',
          age: 32,
          preferences: {
            language: 'zh-CN',
            theme: 'dark',
            notificationSettings: {
              email: true,
              sms: false,
              push: true,
            },
          },
          biometrics: {
            lastLogin: '2024-02-15T08:45:22+08:00',
            deviceFingerprint: 'd3v1c3-f1ng3rpr1nt-v4',
          },
        },
        financial: {
          walletBalance: 4580.5,
          paymentMethods: [
            {
              type: 'creditCard',
              lastFour: '7890',
              expiry: '2026-07',
            },
            {
              type: 'digitalWallet',
              provider: 'WeChat Pay',
            },
          ],
          creditScore: {
            score: 782,
            lastUpdated: '2024-01-31',
          },
        },
        socialGraph: {
          connections: [
            {
              type: 'colleague',
              userId: 'USR-2024-0133',
              since: '2023-11-01',
            },
            {
              type: 'friend',
              userId: 'USR-2024-0198',
              since: '2024-01-15',
            },
          ],
          recommendations: {
            algorithmVersion: 'v3.2.1',
            potentialConnections: ['USR-2024-0301', 'USR-2024-0276'],
          },
        },
        orders: [
          {
            orderId: 'ORD-20240215-25701',
            status: 'shipped',
            logistics: {
              trackingNumber: 'SF123456789CN',
              shippingMethod: 'express',
              routeHistory: [
                {
                  location: '上海仓库',
                  timestamp: '2024-02-15T10:15:00+08:00',
                },
                {
                  location: '北京分拣中心',
                  timestamp: '2024-02-15T14:20:00+08:00',
                },
              ],
            },
            items: [
              {
                productId: 'PROD-EL-1142',
                quantity: 2,
                pricing: {
                  unitPrice: 1599.0,
                  discount: {
                    type: 'seasonal',
                    value: 200.0,
                  },
                  finalPrice: 1399.0,
                },
              },
              {
                productId: 'PROD-ACC-5589',
                quantity: 1,
                pricing: {
                  unitPrice: 299.0,
                  discount: {
                    type: 'bundle',
                    value: 50.0,
                  },
                  finalPrice: 249.0,
                },
              },
            ],
            payment: {
              transactionId: 'PAY-20240215-25701',
              currency: 'CNY',
              taxBreakdown: {
                VAT: 287.6,
                importDuty: 85.4,
              },
            },
          },
        ],
        serviceSubscriptions: [
          {
            serviceId: 'SVC-PREMIUM-2024',
            renewalDate: '2025-02-15',
            features: ['prioritySupport', 'advancedAnalytics', 'customDomain'],
          },
        ],
      },
    ],
    productCatalog: {
      categories: [
        {
          id: 'CT-EL',
          name: '智能家居',
          inventory: [
            {
              productId: 'PROD-EL-1142',
              name: '智能语音助手Pro',
              specifications: {
                processor: '四核A78芯片',
                connectivity: ['WiFi 6', '蓝牙5.2', 'Zigbee'],
                power: {
                  input: '100-240V',
                  battery: '5000mAh',
                },
              },
              compatibility: ['Android 10+', 'iOS 14+'],
              stock: {
                warehouse: 158,
                reserved: 42,
              },
            },
          ],
          // 更多产品...
        },
      ],
      analytics: {
        totalProducts: 1425,
        updateFrequency: 'real-time',
        dataSources: [
          {
            type: 'IoT',
            version: '2.1.3',
            throughput: '1.2M records/sec',
          },
        ],
      },
    },
    geospatial: {
      serviceCenters: [
        {
          id: 'SC-BJ-01',
          coordinates: {
            latitude: 39.9042,
            longitude: 116.4074,
          },
          capacity: 1500,
          supportedServices: ['repair', 'training', 'demo'],
        },
        // 更多服务中心...
      ],
      coverageMap: {
        lastUpdated: '2024-02-01',
        resolution: '5km/pixel',
        dataSize: '2.4GB',
      },
    },
  }
  let rawText = JSON.stringify(reqeustJSON, null, 2)
  const uihelpers = uiHelpers()
</script>

<CodeEditor bind:rawText {uihelpers} />
<DrawerBox {uihelpers} bind:rawText />
